%*******************************************************************************
%*
%*   Copyright ©2009 Alexandru Marin
%*
%*   This file is part of nwave/pMRI C library.
%*
%*   This project started as an MSc degree project during a
%*   stage at the Paris-Est university, under joint supervision of prof.
%*   Bogdan Ionescu (Image Analysis and Processing Laboratory, "Politehica"
%*   University of Bucharest), Caroline Chaux and Jean-Christophe Pesquet
%*   (Laboratoire d'Informatique, Université Paris-Est, Institut Gaspard Monge).
%*
%*   nwave/pMRI C libray is free software: you can redistribute it and/or modify
%*   it under the terms of the GNU General Public License as published by
%*   the Free Software Foundation, either version 2 of the License, or
%*   (at your option) any later version.
%*
%*   nwave/pMRI C libray is distributed in the hope that it will be useful,
%*   but WITHOUT ANY WARRANTY; without even the implied warranty of
%*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%*   GNU General Public License for more details.
%*
%*   You should have received a copy of the GNU General Public License
%*   along with nwave/pMRI C library. If not, see <http://www.gnu.org/licenses/>
%*
%*******************************************************************************

load('mri.mat/I2D');

[N,M] = size(I2D);

load('mri.mat/S2D');
S2D = shiftdim(S2D,2);

L = size(S2D,1);

sb = 8;
Cb = sb^2*eye(L);


disp('* * * Noise generator * * *');


disp('I2D_R2');
tic();
z = mod_pMRI(I2D,S2D,Cb,2);
toc();

disp('I2D_R4');
tic();
z = mod_pMRI(I2D,S2D,Cb,4);
toc();

disp('I2D_R8');
tic();
z = mod_pMRI(I2D,S2D,Cb,8);
toc();

disp('* * * DWT * * *');


disp('DWT I2D_haar_1');
tic();
for i=1:10
    [CA,CH,CV,CD] = dwt2(I2D, 'haar');
end
toc();

disp('IDWT I2D_haar_1');
tic();
for i=1:10
    [CA,CH,CV,CD] = dwt2(I2D, 'haar');
    z = idwt2(CA,CH,CV,CD, 'haar');
end
toc();



disp('DWT I2D_haar_2');
tic();
for i=1:10
[CA,CH,CV,CD] = dwt2(I2D, 'haar');
[CA1,CH1,CV1,CD1] = dwt2(CA, 'haar');
end
toc();

disp('IDWT I2D_haar_2');
tic();
for i=1:10
CA = idwt2(CA1,CH1,CV1,CD1, 'haar');
z = idwt2(CA,CH,CV,CD, 'haar');
end
toc();


disp('DWT I2D_haar_4');
tic();
for i=1:10
[CA,CH,CV,CD] = dwt2(I2D, 'haar');
[CA1,CH1,CV1,CD1] = dwt2(CA, 'haar');
[CA2,CH2,CV2,CD2] = dwt2(CA1, 'haar');
[CA3,CH3,CV3,CD3] = dwt2(CA2, 'haar');
end
toc();

disp('IDWT I2D_haar_4');
tic();
for i=1:10
CA2 = idwt2(CA3,CH3,CV3,CD3, 'haar');
CA1 = idwt2(CA2,CH2,CV2,CD2, 'haar');
CA = idwt2(CA1,CH1,CV1,CD1, 'haar');
z = idwt2(CA,CH,CV,CD, 'haar');
end
toc();



disp('DWT I2D_db2_2');
tic();
for i=1:10
[CA,CH,CV,CD] = dwt2(I2D, 'db2');
[CA1,CH1,CV1,CD1] = dwt2(CA, 'db2');
end
toc();

disp('IDWT I2D_db2_2');
tic();
for i=1:10
CA = idwt2(CA1,CH1,CV1,CD1, 'db2');
z = idwt2(CA,CH,CV,CD, 'db2');
end
toc();


disp('DWT I2D_db2_4');
tic();
for i=1:10
[CA,CH,CV,CD] = dwt2(I2D, 'db4');
[CA1,CH1,CV1,CD1] = dwt2(CA, 'db4');
end
toc();

disp('IDWT I2D_db2_4');
tic();
for i=1:10
CA = idwt2(CA1,CH1,CV1,CD1, 'db4');
z = idwt2(CA,CH,CV,CD, 'db4');
end
toc();


disp('DWT I2D_db2_8');
tic();
for i=1:10
[CA,CH,CV,CD] = dwt2(I2D, 'db8');
[CA1,CH1,CV1,CD1] = dwt2(CA, 'db8');
end
toc();

disp('IDWT I2D_db2_8');
for i=1:10
tic();
CA = idwt2(CA1,CH1,CV1,CD1, 'db8');
z = idwt2(CA,CH,CV,CD, 'db8');
end
toc();
